<?php

class model_purchaseUrl extends L {

    /**
     * 描述 ：分页的查询语句拼接
     * 作者 ：Zoro.ZHu
    **/
    public static function searchSql($params = array()){
        $sql = "SELECT
             `itemId`, `url`, `sku`, `purchaseUrl`, `addTime`, `data`, `clearance`
        FROM
            `purchase_url`
        WHERE 1";

        $sql .= !empty($params['search']['itemId']) ? " AND `itemId` LIKE '%{$params['search']['itemId']}%' " : "";
        $name = core_base::getUser('name');
        if($sku = of_base_com_kv::get('purchaseUrlSpu' . '::' . $name)){
//            of_base_com_kv::del('purchaseUrlSpu');
            $sql .= " AND `sku` LIKE '%{$sku}%' ";
        }
        return $sql;
    }

    /**
     * 描述 ：执行修改数据的sql
     * 作者 ：Zoro.ZHu
    **/
    public static function updateSql($data = array()){
        $sql = "UPDATE `purchase_url` 
        SET 
            `url` = '{$data['url']}',
            `sku` = '{$data['sku']}',
            `purchaseUrl` = '{$data['purchaseUrl']}',
            `addTime` = '{$data['addTime']}',
            `data` = '{$data['data']}'
        WHERE
            `itemId` = '{$data['itemId']}'";
        return L::sql($sql);
    }

    /**
     * 描述 ：执行插入数据的sql
     * 作者 ：Zoro.ZHu
    **/
    public static function insertSql($data = array()){
        $sql = "INSERT INTO `purchase_url`(
             `url`, `sku`, `purchaseUrl`, `addTime`, `data`
        ) VALUES (
             '{$data['url']}', '{$data['sku']}', '{$data['purchaseUrl']}', '{$data['addTime']}', '{$data['data']}'
        )";
        return L::sql($sql);
    }

    /**
     * 描述：根据主键获取数据
     * 作者：Zoro.ZHu
    **/
    public static function getKeyInfo($key){
        $sql = "SELECT
             `itemId`, `url`, `sku`, `purchaseUrl`, `addTime`, `data`
        FROM
            `purchase_url`
        WHERE 
            `itemId` = '{$key}'";
        return L::sql($sql);
    }

}